package com.quanlei.tools;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class DoubanUtil {
	public static String apiKey = "05bcd1326532164a113673972f9642de";
	public static String secret = "8194622cd9e873a8";
	public static String callback = "haiyang://callback";

	public static JSONArray getDoubanMusic() {
		try {
			URL url = new URL(
					"http://douban.fm/j/mine/playlist?type=n&channel=0");
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			conn.setRequestMethod("GET");
			if (conn.getResponseCode() == 200) {
				BufferedReader buff = new BufferedReader(new InputStreamReader(
						conn.getInputStream()));
				String line = "";
				JSONObject json = null;
				while ((line = buff.readLine()) != null) {
					json = new JSONObject(line);
				}
				Log.i("key:", json.getJSONArray("song").getJSONObject(0)
						.getString("url"));
				return json.getJSONArray("song");
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}

}
